// pages/tabBar/my/myFollow/index.js
const http = require("../../../../utils/httpUtils.js");
const app = getApp();
Page({
    data: {
        navbarData: {
            showCapsule: 1, //是否显示左上角图标
            title: '我的关注' //导航栏 中间的标题
        },
        height: app.globalData.height * 2 + 20
    },

    onLoad: function(options) {
        this.getList(1)
    },
    getList(pageNum) {
        http._headerGet('/api/user/my_attention', {
            "page": pageNum,
            "c_client": "weixinSmall"
        }, res => {
            if (res.data.code == 1) {
                if (res.data.data.length != 0) {
                    this.setData({
                        list: res.data.data,
                        pageNum: pageNum
                    })
                } else {
                    wx.showToast({
                        title: `暂无数据`,
                        duration: 2000,
                        icon: 'none'
                    })
                }
            } else {
                wx.showToast({
                    title: res.data.msg,
                    duration: 2000,
                    icon: 'none'
                })
            }
            wx.stopPullDownRefresh()
        })

    },
    removeconc(e) {
        let index = e.currentTarget.dataset.index;
        let _data = {
            c_client: "weixinSmall",
            user_id: this.data.list[index].u_id
        }
        http._headerPost('/api/user/del_attention', _data, res => {
            if (res.data.code == 1) {
                this.data.list.splice(index, 1);
                this.setData({
                    list: this.data.list
                })
                wx.showToast({
                    title: res.data.msg,
                    duration: 2000,
                    icon: 'success'
                })
            } else {
                wx.showToast({
                    title: res.data.msg,
                    duration: 2000,
                    icon: 'none'
                })
            }
        })
    },

    // 下拉刷新
    onPullDownRefresh: function() {
        this.getList(1)
    },
    // 上拉加载
    onReachBottom: function() {
        this.getList(this.data.pageNum + 1)
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})